import layoutHeaderAside from '@/layout/header-aside'

// 由于懒加载页面太多的话会造成webpack热更新太慢，所以开发环境不使用懒加载，只有生产环境使用懒加载
const _import = require('@/libs/util.import.' + process.env.NODE_ENV)

/**
 * 在主框架内显示
 */
const frameIn = [
  {
    path: '/',
    redirect: { name: 'index' },
    component: layoutHeaderAside,
    children: [
      // 首页
      {
        path: 'index',
        name: 'index',
        meta: {
          auth: true
        },
        component: _import('system/index')
      },
      // 演示页面
      {
        path: 'example',
        name: 'example',
        meta: {
          title: '样例',
          auth: true
        },
        component: _import('example')
      },
      {
        path: 'user',
        name: 'user',
        meta: {
          title: '用户浏览',
          auth: true
        },
        component: _import('user')
      },
      {
        path: 'user/create',
        name: 'user_create',
        meta: {
          title: '用户新增',
          auth: true
        },
        component: _import('user/create')
      },
      {
        path: 'batch',
        name: 'batch',
        meta: {
          title: '订单浏览',
          auth: true
        },
        component: _import('batch')
      },
      {
        path: 'batch/create',
        name: 'batch_create',
        meta: {
          title: '订单新增',
          auth: true
        },
        component: _import('batch/create')
      },
      {
        path: 'packet',
        name: 'packet',
        meta: {
          title: '包装盒浏览',
          auth: true
        },
        component: _import('packet')
      },
      {
        path: 'packet/category',
        name: 'packet_category',
        meta: {
          title: '包装盒类别浏览',
          auth: true
        },
        component: _import('packet/category')
      },
      {
        path: 'packet/categoryCreate',
        name: 'packet_categoryCreate',
        meta: {
          title: '包装盒类别新增',
          auth: true
        },
        component: _import('packet/categoryCreate')
      },
      {
        path: 'packet/create',
        name: 'packet_create',
        meta: {
          title: '包装盒新增',
          auth: true
        },
        component: _import('packet/create')
      },
      {
        path: 'material',
        name: 'material',
        meta: {
          title: '原料浏览',
          auth: true
        },
        component: _import('material')
      },
      {
        path: 'material/create',
        name: 'material_create',
        meta: {
          title: '原料新增',
          auth: true
        },
        component: _import('material/create')
      },
      {
        path: 'material/category',
        name: 'material_category',
        meta: {
          title: '原料类别浏览',
          auth: true
        },
        component: _import('material/category')
      },
      {
        path: 'material/categoryCreate',
        name: 'material_categoryCreate',
        meta: {
          title: '原料类别新增',
          auth: true
        },
        component: _import('material/categoryCreate')
      },
      {
        path: 'trace',
        name: 'trace',
        meta: {
          title: '追溯',
          auth: true
        },
        component: _import('trace')
      },
      {
        path: 'product',
        name: 'product',
        meta: {
          title: '产品浏览',
          auth: true
        },
        component: _import('product')
      },
      {
        path: 'product/category',
        name: 'product_category',
        meta: {
          title: '产品类别浏览',
          auth: true
        },
        component: _import('product/category')
      },
      {
        path: 'product/categoryCreate',
        name: 'product_categoryCreate',
        meta: {
          title: '产品类别新建',
          auth: true
        },
        component: _import('product/categoryCreate')
      },
      {
        path: 'supplier',
        name: 'supplier',
        meta: {
          title: '供应商浏览',
          auth: true
        },
        component: _import('supplier')
      },
      {
        path: 'supplier/create',
        name: 'supplier_create',
        meta: {
          title: '供应商新增',
          auth: true
        },
        component: _import('supplier/create')
      },
      // 刷新页面 必须保留
      {
        path: 'refresh',
        name: 'refresh',
        hidden: true,
        component: _import('system/function/refresh')
      },
      // 页面重定向 必须保留
      {
        path: 'redirect/:route*',
        name: 'redirect',
        hidden: true,
        component: _import('system/function/redirect')
      }
    ]
  }
]

/**
 * 在主框架之外显示
 */
const frameOut = [
  // 登录
  {
    path: '/login',
    name: 'login',
    component: _import('system/login')
  }
]

/**
 * 错误页面
 */
const errorPage = [
  {
    path: '*',
    name: '404',
    component: _import('system/error/404')
  }
]

// 导出需要显示菜单的
export const frameInRoutes = frameIn

// 重新组织后导出
export default [
  ...frameIn,
  ...frameOut,
  ...errorPage
]
